package ch.bfh.abcmmh.testsuite.testclasses;

import junit.framework.Assert;

import org.junit.Test;

import ch.bfh.abcmmh.controller.operating.scanner.StreetScanner;
import ch.bfh.abcmmh.model.streetutils.Street;

public class StreetScannerTester {

	@Test
	public void distanceAhead() {
		
		Street street = new Street(100);
		street.setSAttributeVehicle(3,null);
		for (int i = 0; i < 10; i++) {
			Assert.assertTrue(street.getSAttribute(4+i).isFree());
		}
		street.setSAttributeVehicle(14,null);
		StreetScanner streetScanner = new StreetScanner(street);
		Assert.assertEquals(10, streetScanner.getDistObstacleAhead(3));
		Assert.assertEquals(0, streetScanner.getDistObstacleAhead(13));
		Assert.assertEquals(5, streetScanner.getDistObstacleAhead(8));
		Assert.assertEquals(200, streetScanner.getDistObstacleAhead(20));
	}

	@Test
	public void distanceBehind() {
		Street street2 = new Street(50);
		for (int i = 0; i < street2.getHighestIndex()+1; i++) {
			Assert.assertTrue(street2.getSAttribute(i).isFree());
		}
		
		street2.setSAttributeVehicle(9,null);
		street2.setSAttributeVehicle(19,null);
		street2.setSAttributeVehicle(29,null);
		
		StreetScanner scanner = new StreetScanner(street2);
		
		Assert.assertEquals(8, scanner.getDistObstacleBehind(8));
		Assert.assertEquals(0, scanner.getDistObstacleBehind(10));
		Assert.assertEquals(0, scanner.getDistObstacleBehind(9));
		Assert.assertEquals(6, scanner.getDistObstacleBehind(16));
		Assert.assertEquals(3, scanner.getDistObstacleBehind(33));
		Assert.assertEquals(15, scanner.getDistObstacleBehind(45));
	
	}
}
